import {UPLOAD_URl} from '@/config/index.js'
// 全局跳转
const go=(url)=>{
	// 判断路径是不是tabbar path
	let pagesConfig = require('@/pages.json')
	let tabbarList=pagesConfig.default.tabBar.list
	let tabbar = tabbarList.map(item=>'/'+item.pagePath)
	// console.log(tabbar);x
	if(tabbar.includes(url)){
		uni.switchTab({
			url
		})
	}else{
		uni.navigateTo({
			url:url
		})
	}
	
}
const upload =(tempFilePaths)=>{
	return new Promise((reslove,reject)=>{
		uni.showLoading({
			title:'上传中...'
		})
		uni.uploadFile({
			url: UPLOAD_URl, //仅为示例，非真实的接口地址
			filePath: tempFilePaths,
			name: 'file',
			header: {
			    'Authorization': uni.getStorageSync('token') //自定义请求头信息
			},
			formData: {},
			success: (uploadFileRes) => {
				reslove(JSON.parse(uploadFileRes.data))
				uni.hideLoading()
			},
			fail(error) {
				uni.hideLoading()
				reject(error)
			}
		});
	})

}
const go1=()=>{
	wx.navigateBack()
}
export default {
	go,go1,upload
}